//
// Created by 25313 on 2025/8/5.
//
class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int> max_queue(stones.begin(), stones.end());
        while (max_queue.size() > 1) {
            int x = max_queue.top();
            max_queue.pop();
            int y = max_queue.top();
            max_queue.pop();
            x -= y;
            max_queue.push(x);
        }
        return max_queue.size() == 1 ? max_queue.top() : 0;
    }
};